package com.flying.common.annotation.handler;

import java.lang.annotation.Annotation;
import java.sql.Date;
import java.sql.JDBCType;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;

import com.flying.framework.service.ServiceHandler;

public abstract class AbstractDaoServiceHandler<T extends Annotation> implements ServiceHandler<T>  {
	protected void setPreparedStatementParam(PreparedStatement pstmt, int index, Object value) throws SQLException {
		if(value == null) {
			pstmt.setNull(index, JDBCType.VARCHAR.getVendorTypeNumber());
		} else if(value instanceof String) {
			pstmt.setString(index, (String)value);
		} else if(value instanceof Integer) {
			pstmt.setInt(index, (Integer)value);
		} else if(value instanceof Long) {
			pstmt.setLong(index, (Long)value);
		} else if(value instanceof Date) {
			pstmt.setDate(index, (Date)value);
		} else if(value instanceof Timestamp) {
			pstmt.setTimestamp(index, (Timestamp)value);
		} else if(value instanceof java.util.Date) {
			java.util.Date d = (java.util.Date)value;
			pstmt.setTimestamp(index, new Timestamp(d.getTime()));
		} else {
			pstmt.setObject(index, value);
		}
	}
}
